import 'package:flutter/material.dart';
import 'package:xunlongchi/util/app_util.dart';

///构建分秒
class RoundSed extends StatefulWidget {
  const RoundSed({Key key}) : super(key: key);

  @override
  _RoundSedState createState() => _RoundSedState();
}

class _RoundSedState extends State<RoundSed> {
  bool _ready = false;

  @override
  void initState() {
    super.initState();

    () async {
      await Future.delayed(const Duration(milliseconds: 1600), () {
        setState(() {
          _ready = true;
        });
      });
    }();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedOpacity(
      opacity: _ready ? 1 : 0,
      duration: const Duration(milliseconds: 500),
      child: SedBody(),
    );
  }
}

class SedBody extends StatelessWidget {
  const SedBody({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final double _sizeSed = 1080.px;

    final List<Widget> _num = Iterable<int>.generate(30)
        .toList()
        .map((i) => RotationTransition(
              turns: AlwaysStoppedAnimation(-6 * i / 360 - 90 / 360),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  RotatedBox(quarterTurns: -1, child: Text('${i + 30}')),
                  RotatedBox(quarterTurns: 1, child: Text('$i')),
                ],
              ),
            ))
        .toList();

    return SizedBox(
      width: _sizeSed,
      height: _sizeSed,
      child: DefaultTextStyle(
        style: TextStyle(
          color: Colors.deepPurple,
          fontWeight: FontWeight.bold,
          fontSize: 30.sp,
          fontFamily: 'OS',
        ),
        child: Stack(
          alignment: Alignment.center,
          children: _num,
        ),
      ),
    );
  }
}
